import esriLoader from 'esri-loader'

var addLayer = function (layers) {
  esriLoader.loadModules(["esri/layers/ArcGISDynamicMapServiceLayer"])
    .then(([ArcGISDynamicMapServiceLayer]) => {
      for (var i = 0; i<layers.length;i++){
        if(layers[i].ILayer){
          var layer = new ArcGISDynamicMapServiceLayer(layers[i].ILayer.DisplayUrl,{
            id: layers[i].ILayer.LayerName,
            dpi: layers[i].ILayer.QueryIndexArray
          });
          esriMap.addLayer(layer);
        }
      }
    })
    .catch(err => {
      // handle any script or module loading errors
      console.error(err);
    });
}
export default {
  addLayer
}
